﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PDFTool
{
    public partial class FrmSplit : Form
    {
        public int TotalPage { get; set; }
        public int StartPage { get; set; }
        public int EndPage { get; set; }
        public string FileName { get; set; }
        public FrmSplit()
        {
            InitializeComponent();
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            StartPage = Convert.ToInt32(txtStartPage.Text.Trim());
            EndPage = Convert.ToInt32(txtEndPage.Text.Trim());
            FileName = txtFileName.Text.Trim();

            if (StartPage > EndPage || StartPage < 1 || EndPage > TotalPage)
            {
                MessageBox.Show("页码范围设置不正确");
                return;
            }

            if (FileName.Length == 0)
            {
                MessageBox.Show("未设置导出文件名");
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void txtStartPage_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x20) e.KeyChar = (char)0;  //禁止空格键 
            if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return;   //处理负数 
            if (e.KeyChar > 0x20)
            {
                try
                {
                    double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
                }
                catch
                {
                    e.KeyChar = (char)0;   //处理非法字符 
                }
            }
        }
    }
}
